*********************
** Table 2: Parents’ perceptions of the refugee crisis: Average agreement on a scale from 1 (totally disagree) to 10 (totally agree)
*********************
* Relabel Variables
local index = "i"
foreach v of varlist ParAtt_* {
	label variable `v' `"(`index') `: variable label `v''"'
	if "`index'" == "iii" local index = "iv"
	if "`index'" == "ii" local index = "iii"
	if "`index'" == "i" local index = "ii"
}

* Create Table
local variables "ParAtt_Tragedy ParAtt_JordanDoneEnough ParAtt_RentalPrice ParAtt_Jobs"
di "`variables'"

local nVariables: word count `variables'
di "`nVariables'"

qui su shift, detail
if `r(max)' <= 2 {
	mat T = J(`nVariables',6,.)
	local i = 1

	foreach variable of local variables {
	ttest `variable', by(shift)
	mat T[`i',1] = r(mu_1)
	mat T[`i',3] = r(mu_2)
	mat T[`i',5] = r(p)
	mat T[`i',2] = r(sd_1)
	mat T[`i',4] = r(sd_2)
	mat T[`i',6] = .
	local i = `i' + 1
	}

	su `variables' if shift == 0
	local nCluster1 = `r(N)'
	su `variables' if shift == 1
	local nCluster2 = `r(N)'

	mat rownames T = ParAtt_Tragedy ParAtt_JordanDoneEnough ParAtt_RentalPrice ParAtt_Jobs
	
	frmttable using "2_output\Table2.doc", statmat(T) substat(1) sdec(1, 1, 2) varlabels replace ///
	ctitle("Perception", "Parents of Children in Morning Shift", "Parents of Children in Afternoon Shift", "p(Diff {&ne} 0)") ///
	addrows("N", "`nCluster1'", "`nCluster2'") ///
	note("Notes: Standard deviations in parentheses.") ///
	title("Table 2: Parents' perceptions of the refugee crisis: Average agreement on a scale from 1 (totally disagree) to 10 (totally agree)")
}

* Undo: Relabel Variables
foreach v of varlist ParAtt_* {
	local label = `"`: variable label `v''"'
	local label = substr("`label'",strpos("`label'",")")+1,.)
	label variable `v' "`label'"
}

* Have a nice day!
